package gunfire.relics;

import basemod.abstracts.CustomRelic;
import com.badlogic.gdx.graphics.Texture;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.animations.VFXAction;
import com.megacrit.cardcrawl.actions.common.*;
import com.megacrit.cardcrawl.actions.utility.SFXAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.DexterityPower;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import com.megacrit.cardcrawl.rooms.AbstractRoom;
import com.megacrit.cardcrawl.vfx.combat.CleaveEffect;
import gunfire.GunfireMod;
import gunfire.util.TextureLoader;

import static gunfire.GunfireMod.makeRelicOutlinePath;
import static gunfire.GunfireMod.makeRelicPath;

public class SoulOfIron1 extends CustomRelic {

    public static final String ID = GunfireMod.makeID("SoulOfIron1");
    private static final Texture IMG = TextureLoader.getTexture(makeRelicPath("SoulOfIron1.png"));
    private static final Texture OUTLINE = TextureLoader.getTexture(makeRelicOutlinePath("blank.png"));

    public SoulOfIron1() {
        super(ID, IMG, OUTLINE, RelicTier.SPECIAL, LandingSound.CLINK);
    }

    @Override
    public String getUpdatedDescription() {
        return DESCRIPTIONS[0];
    }

    @Override
    public void obtain() {
        if (AbstractDungeon.player.hasRelic("gunfire:SoulOfIron")) {
            for(int i = 0; i < AbstractDungeon.player.relics.size(); ++i) {
                if (AbstractDungeon.player.relics.get(i).relicId.equals(SoulOfIron.ID)) {
                    this.instantObtain(AbstractDungeon.player, i, true);
                    break;
                }
            }
        } else {
            super.obtain();
        }
    }

    @Override
    public void onEquip() {
        AbstractDungeon.player.energy.energy++;
        AbstractDungeon.player.energy.energyMaster++;
        AbstractDungeon.player.increaseMaxHp(50, true);
        if(AbstractDungeon.getCurrRoom().phase == AbstractRoom.RoomPhase.COMBAT){
            this.flash();
            this.addToBot(new ApplyPowerAction(AbstractDungeon.player, AbstractDungeon.player, new DexterityPower(AbstractDungeon.player, 1), 1));
            this.addToBot(new RelicAboveCreatureAction(AbstractDungeon.player, this));
        }
    }

    @Override
    public void onUnequip() {
        AbstractDungeon.player.energy.energyMaster--;
    }

    @Override
    public void atBattleStart() {
        this.flash();
        this.addToBot(new ApplyPowerAction(AbstractDungeon.player, AbstractDungeon.player, new DexterityPower(AbstractDungeon.player, 3), 3));
        this.addToBot(new RelicAboveCreatureAction(AbstractDungeon.player, this));
    }

    @Override
    public void atTurnStart() {
        this.flash();
        this.addToBot(new HealAction(AbstractDungeon.player, AbstractDungeon.player, 8));
    }

    @Override
    public void wasHPLost(int damageAmount) {
        if (damageAmount > 0) {
            this.flash();
            this.addToBot(new HealAction(AbstractDungeon.player, AbstractDungeon.player, 3));
        }
    }

    @Override
    public int onPlayerGainedBlock(float blockAmount) {
        this.flash();
        if(AbstractDungeon.getMonsters() != null && blockAmount > 0){
            AbstractMonster m = AbstractDungeon.getRandomMonster();
            this.addToBot(new DamageAction(m, new DamageInfo(AbstractDungeon.player, (int)blockAmount, DamageInfo.DamageType.HP_LOSS), AbstractGameAction.AttackEffect.BLUNT_LIGHT));
        }
        return 0;
    }

    @Override
    public int onPlayerHeal(int healAmount) {
        AbstractPlayer p = AbstractDungeon.player;
        int overHeal = Math.max(0, p.currentHealth + healAmount - p.maxHealth);
        if(AbstractDungeon.getMonsters() != null && overHeal > 0){
            AbstractMonster m = AbstractDungeon.getRandomMonster();
            this.addToBot(new DamageAction(m, new DamageInfo(AbstractDungeon.player, overHeal, DamageInfo.DamageType.HP_LOSS), AbstractGameAction.AttackEffect.BLUNT_LIGHT));
        }
        return super.onPlayerHeal(healAmount);
    }

    @Override
    public void onVictory() {
        this.flash();
        AbstractDungeon.player.heal(15);
        //this.addToBot(new HealAction(AbstractDungeon.player, AbstractDungeon.player, 15));
    }

    @Override
    public AbstractRelic makeCopy() {
        return new SoulOfIron1();
    }
}
